//
// Created by 67678 on 2023/3/17.
//
#include "dateBase.h"
#include <string>
#include <sstream>
#include <cstdio>
#include <thread>
#include <iostream>
#include<algorithm>
#include <random>
#include <cassert>
#include "../../util/timeit.h"


using namespace std;
using namespace dateBase;

class RandomString {
public:
    RandomString() {
        for (char ch = 'a'; ch <= 'z'; ++ch) {
            str_.push_back(ch);
            str_.push_back(ch + 'A' - 'a');
        }
    }

    string get(int n) {
        string ret;
        ret.reserve(n);
        sample(str_.begin(), str_.end(), std::back_inserter(ret), n,
               std::mt19937{std::random_device{}()});
        return ret;
    }

private:
    string str_;
};

void test(int nums, int len) {
    DateBase &dateBase = DateBase::getInstance();
    RandomString randomString;
    vector<string> strs;
    strs.reserve(nums);
    for (int i = 0; i < nums; ++i)
        strs.push_back(randomString.get(len));

    auto fun = [&]() {
        for (string str: strs) {
            dateBase.set(str, str);
            assert(dateBase.get(str) == str);
        }
    };
    cout << "dateBase test begin!" << endl;
    util::time_it(fun);
    cout << "dateBase test end!" << endl;

}

int main() {
    test(1000, 6);
    test(10000, 6);
    test(100000, 6);
    test(1000, 60);
    test(10000, 60);
    test(100000, 60);
    test(1000, 600);
    test(10000, 600);
    test(100000, 600);
}